﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Core.Query.DishModule.ViewObject;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;

namespace Resto.CostControl.Core.Query.DishModule.QueryObject
{
    public class DishQO : IApplicationQueryObject
    {
        private IQueryable<DishVO> GetDishVOSet()
        {
            IEntityRepository<Dish> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<Dish>();

            IQueryable<DishVO> list = from o in repository.Objects
                                          where o.IsDelete == false
                                          select new DishVO()
                                         {
                                             ID = o.ID,
                                             Code = o.Code,                                             
                                             Name = o.Name,
                                             Category = o.Category,
                                             CookType = o.CookType,
                                             Cost = o.Cost,
                                             Price = o.Price,
                                             MainMaterialCategory = o.MainMaterialCategory
                                         };

            return list;
        }

        public DishVO[] QueryDishVOByPager(ISpecification<DishVO> spec, PagerCondition pager, string orderKey, bool isAscending)
        {
            IQueryable<DishVO> list = GetDishVOSet();

            if (spec != null)
                list = list.Where(spec.GetExpression());

            IEnumerable<DishVO> list2 = RepositoryExtention.Query(list, pager, orderKey, isAscending);
            return list2.ToArray();
        }
    }
}
